var pageSize = 10;
var pageNum = 1;
var page;
var laypage;



$(function () {
    $("#menuId").val(sessionStorage.menuId);
    // alert("000"+sessionStorage.menuId);
    layui.use(['laydate','element','laypage','layer'], function(){
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        element = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层

        //以上模块根据需要引入



    });
    setTimeout(function () {
        findIncomeDetail();
    },200);

});


//查看明细
function findIncomeDetail() {
    var menuId = $("#menuId").val();
    var userId = sessionStorage.incomeUserId;
    var incomeType = $("#incomeType").val();
    var params = {
        "type":"query",
        "menuId":menuId,
        "userId":userId,
        "pageSize":pageSize,
        "pageNum":pageNum,
        "incomeType":incomeType
    };
    $.ajax({
        type:"post",
        url: "/agent/findIncomeDetail",
        data:params,
        dataType: "json",
        success : function(data){
            if(data.code = 1 && data.code != undefined){
                page = data.page;
                var aic = data.agentIncomeDetailNews;
                var html = "";
                for(var b in aic){
                    var incomeType = "";
                    if(aic[b].incomeType == 11){
                        incomeType = "商家发广告收益";
                    }else if(aic[b].incomeType == 21){
                        incomeType = "区域广告收益";
                    }else if(aic[b].incomeType == 31){
                        incomeType = "推荐收益";
                    }else if(aic[b].incomeType == 41){
                        incomeType = "优惠买单收益";
                    }
                    var triggerIncomeName = "";
                    if(aic[b].triggerIncomeName != undefined){
                        triggerIncomeName = aic[b].triggerIncomeName;
                    }
                    var triggerIncomePhone = "";
                    if(aic[b].triggerIncomePhone != undefined){
                        triggerIncomePhone = aic[b].triggerIncomePhone;
                    }
                    html += '<tr><td>'+(parseInt(b)+parseInt(1))+'</td>'+
                        '<td>'+incomeType+'</td>'+
                        '<td>'+aic[b].sourceAmount/100+'</td>'+
                        '<td>'+aic[b].incomeParam+'</td>'+
                        '<td>'+aic[b].incomeAmount/100+'</td>'+
                        '<td>'+new Date(aic[b].createTime).toLocaleString()+'</td>'+
                        '<td>'+triggerIncomeName+'</td>'+
                        '<td>'+triggerIncomePhone+'</td></tr>';
                }
                $("#bus").html(html);
                $("#total").html("共有数据："+page.total+" 条");
                laypage({
                    cont: 'page'
                    ,pages: page.pages
                    ,first: 1
                    ,curr:pageNum
                    ,last: page.pages
                    ,prev: '<em><</em>'
                    ,next: '<em>></em>'
                    ,jump: function (obj,first) {
                        pageNum = obj.curr;
                        if(!first){
                            findIncomeDetail();
                        }
                    }
                });
            }else if(data == 9999 && data != undefined){
                window.location.href = "/login_toLogin";
            }else if(data == 1111 && data != undefined){
                alert("无权操作");
            }else if(data.code = 2 && data.code != undefined){
                $("#bus").html("");
            }
        }

    });
}
//查询按钮
function search() {
    pageNum = 1;
    findIncomeDetail();
}